package com.bdy.lm.browser.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.bdy.lm.common.model.Driver;

@Repository("driverDao")
public class DriverDao {
	
	@Autowired
	private SessionFactory sessionFactory;
	
    public boolean addDriver(Driver driver) {
    	sessionFactory.getCurrentSession().save(driver);
		return true;
	}
    
	@SuppressWarnings("unchecked")
    public Driver queryDriver(Driver driver) {
    	String hql = "from Driver d where d.identityNum = '" + driver.getIdentityNum() + "'";
		List<Driver> drivers = sessionFactory.getCurrentSession().createQuery(hql).list();
		if (drivers!= null && drivers.size() == 1) {
			return drivers.get(0);
		}
		return null;
	}
	
	public void deleteDriver(Driver driver) {
		sessionFactory.getCurrentSession().delete(driver);
	}
	
	public void uodateDriver(Driver driver) {
		sessionFactory.getCurrentSession().update(driver);
	}
}
